home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / obj_exp / obj.c next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  5.9 KB  |  273 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <egb.h>
  6. #include <spr.h>
  7. #include <snd.h>
  8. #include <fif.h>
  9. #include <fmc.h>
  10.  
  11. #define VERSION "1.02"
  12. #define    SPRNUM    1024-160
  13. #define ESC        0x1b
  14. #define RIGHT    0x1c
  15. #define LEFT    0x1d
  16. #define UP        0x1e
  17. #define DOWN    0x1f
  18.  
  19. char path[]="q:\\data\\";
  20. char buffer[0x20000];
  21. char col[8192];
  22. char idx[500][250];
  23. char dat[50][20482];
  24. char egb_work[1536], msg[256];
  25. char same[256];
  26. int number=0, number_max, param=0, param_max, pal=0, pal_max, direction=1;
  27. int key, shift, ctrl, color=0, sx, sy, rx=0, ry=0, mul=2;
  28. FILE *fp;
  29.  
  30. extern void crtcout(int crtcreg, int data);
  31. extern void save_r(char *buffer);
  32. extern void load_r(char *buffer);
  33. extern void print_3(int x, int y, int col, char *str, int len);
  34.  
  35.  
  36. char joy_stick()
  37. {
  38.     char s, mem=0xff;
  39.     int cnt, status;
  40.     do {
  41.         SND_joy_in_2(0, &status);
  42.         s = ~status;
  43.         SND_joy_in_2(1, &status);
  44.         s |= ~status;
  45.         if (s!=mem) {
  46.             cnt=0;
  47.             mem=s;
  48.         }
  49.     } while (++cnt<16);
  50.     return s;
  51. }
  52.  
  53. char joy_repeat()
  54. {
  55.     static char cnt, mem=0xff;
  56.     int s;
  57.     if ((s=joy_stick())!=mem) {
  58.         cnt=0;
  59.         return mem=s;
  60.     }
  61.     if (++cnt<32) return 0;
  62.     cnt--;
  63.     return s;
  64.  
  65. void scroll()
  66. {
  67.     int i;
  68.     i=joy_repeat();
  69.     if (i & 1) ry--;
  70.     if (i & 2) ry++;
  71.     if (i & 4) rx--;
  72.     if (i & 8) rx++;
  73.     if (i==0x10 && mul<16) mul++;
  74.     if (i==0x20 && mul>2) mul--;
  75.     if (i & 0xc0) {
  76.             mul=2;
  77.             rx=ry=0;
  78.     }
  79.     if (_abs(rx)>(i=sx*8)) rx=(rx>=0 ? i: -i);
  80.     if (_abs(ry)>(i=sy*8)) ry=(ry>=0 ? i: -i);
  81.     SPR_setPosition(0, SPRNUM, sx, sy, 256/mul-sx*8-rx, 336/mul-sy*8-ry);
  82.     crtcout(27, (mul-1)*0x1100+0x11);
  83.     SPR_display(2, 160);
  84. }
  85.  
  86. void print_msg(x, y, col)
  87. int x, y, col;
  88. {
  89.     print_3(x, y, col, msg, strlen(msg));
  90. }
  91.  
  92. void input(sw)
  93. int sw;
  94. {
  95.     unsigned i;
  96.     key=KYB_read(sw, &i);
  97.     shift=i & 4;
  98.     ctrl=i & 0x10;
  99. }
  100.  
  101. void sprite_erase()
  102. {
  103. /*    SPR_setPosition(0, SPRNUM, 16, 10, 256, 0);*/
  104.     SPR_setAttribute(SPRNUM, 16, 10, 0, 0xa100);
  105. }
  106.  
  107. void print_block()
  108. {
  109.     int i=same[pal];
  110.     sprintf(msg, "PALETTE BLOCK %3d (%02X)", i, i);
  111.     print_msg(5, 3, 7);
  112.     sprintf(msg, "PALETTE SORT %3d (Max %3d)", pal, pal_max-1);
  113.     print_msg(5, 4, 7);
  114.     SPR_setAttribute(SPRNUM, sx, sy, 128, same[pal]+0x8100);
  115. }
  116.  
  117. void display_object()
  118. {
  119.     char *ptr;
  120.     int i=-1;
  121.     param=(direction>=0 ? 0 : param_max-1);
  122.     for (;;) {
  123.         if (param!=i) {
  124.             ptr=&idx[number][(i=param)*5];
  125.             sprite_erase();
  126.             SPR_define(0, 128, sx=ptr[0], sy=ptr[1], &dat[i][0]);
  127.             sprintf(msg, "OBJECT NUMBER %2d - %2d (Max %2d)", number+1, i+1, param_max);
  128.             print_msg(5, 1, 7);
  129.             sprintf(msg, "INDEX DATA %02X %02X %02X %02X %02X", sx, sy, ptr[2], ptr[3], ptr[4]);
  130.             print_msg(5, 2, 7);
  131.             print_block();
  132.         }
  133.         scroll();
  134.         input(1);
  135.         switch (key) {
  136.             case ESC:
  137.                 return;
  138.             case UP:
  139.                 pal -= (ctrl ? (shift ? 0x40 : 0x20) : (shift ? 0x10 : 1));
  140.                 break;
  141.             case DOWN:
  142.                 pal += (ctrl ? (shift ? 0x40 : 0x20) : (shift ? 0x10 : 1));
  143.                 break;
  144.             case RIGHT:
  145.                 if (shift==0 && ctrl==0 && ++param<param_max) continue;
  146.                 direction=+(ctrl ? (shift ? 20 : 5) : 1);
  147.                 return;
  148.             case LEFT:
  149.                 if (shift==0 && ctrl==0 && --param>=0) continue;
  150.                 direction=-(ctrl ? (shift ? 20 : 5) : 1);
  151.                 return;
  152.             default:
  153.                 continue;
  154.         }
  155.         while (pal<0) pal+=pal_max;
  156.         while (pal>=pal_max) pal-=pal_max;
  157.         print_block();
  158.     }
  159. }
  160.  
  161. void clear_msg()
  162. {
  163.     strcpy(msg, "                                          ");
  164.     print_msg(0, 7, 7);
  165.     print_msg(0, 8, 7);
  166.     if (++color==7) color++;
  167.     if (color>=15) color=0;
  168. }
  169.  
  170. void display_main()
  171. {
  172.     char *ptr;
  173.     int i;
  174.     strcpy(msg, "オブジェクト表示  Ver" VERSION "  by Yasu.Hara.");
  175.     print_msg(0, 0, 15);
  176.     do {
  177.         strcpy(msg, "データを読み込んでいま~すっ ☆彡");
  178.         print_msg(4, 7, color);
  179.         strcpy(msg, "ちょっと待ってくださいね~♪(^_^)");
  180.         print_msg(4, 8, color);
  181.         ptr=&idx[number][0];
  182.         for (i=0; i<50; i++)
  183.             if (ptr[i*5]==0 || ptr[i*5+1]==0) break;
  184.         if ((param_max=i)!=0) {
  185.             fseek(fp, number*sizeof(dat), SEEK_SET);
  186.             i--;
  187.             fread(dat, 1, i=i*20482+ptr[i*5]*ptr[i*5+1]*128, fp);
  188.             if (_skip_char(dat, i, 0)<i) {
  189.                 clear_msg();
  190.                 display_object();
  191.                 sprite_erase();
  192.             }
  193.         }
  194.         number+=direction;
  195.         if (number<0) number=number_max-1;
  196.         if (number>=number_max) number=0;
  197.         direction=(direction>=0 ? 1 : -1);
  198.     } while (key!=ESC);
  199. }
  200.  
  201. void file_open(ptr)
  202. char *ptr;
  203. {
  204.     char filename[256];
  205.     sprintf(filename, "%s%s", path, ptr);
  206.     while ((fp=fopen(filename, "rb"))==NULL) {
  207.         if (filename[0]<'q') {
  208.             filename[0]='q';
  209.             continue;
  210.         }
  211.         strcpy(msg, "富士通HabitatのCD-ROMを入れ");
  212.         print_msg(0, 7, color);
  213.         strcpy(msg, "何かキーを押してくださいませぇ~♪(^_^;)");
  214.         print_msg(0, 8, color);
  215.         input(0);
  216.         clear_msg();
  217.         if (key==ESC) exit(1);
  218.     }
  219. }
  220.  
  221. void same_check()
  222. {
  223.     char *ptr;
  224.     int i, j;
  225.     pal_max=0;
  226.     for (i=0; i<256; i++) {
  227.         ptr=&col[i*32];
  228.         for (j=0; j<pal_max; j++) {
  229.             if (memcmp(&col[same[j]*32], ptr, 32)==0) goto SAME_EXIST;
  230.         }
  231.         same[pal_max++]=i;
  232.         SAME_EXIST: ;
  233.     }
  234. }
  235.  
  236. void main(argc, argv)
  237. int argc;
  238. char *argv[];
  239. {
  240.     int i;
  241.     if (argc==2 && (i=(*argv[1]|0x20))>='a' && i<='q') path[0]=i;
  242.     EGB_init(egb_work, sizeof(egb_work));
  243.     EGB_resolution(egb_work, 0, 3);
  244.     EGB_resolution(egb_work, 1, 5);
  245.     EGB_displayPage(egb_work, 0, 3);
  246.     EGB_writePage(egb_work, 1);
  247.     EGB_displayStart(egb_work, 2, 2, 2);
  248.     EGB_displayStart(egb_work, 0, 32, 0);
  249.     EGB_displayStart(egb_work, 3, 256, 256);
  250.     EGB_writePage(egb_work, 0);
  251.     EGB_displayStart(egb_work, 2, 2, 2);
  252.     EGB_displayStart(egb_work, 3, 256, 256);
  253.     SND_elevol_init();
  254.     file_open("palette.32k");
  255.     fread(col, 1, sizeof(col), fp);
  256.     fclose(fp);
  257.     file_open("object.idx");
  258.     number_max=fread(idx, 1, sizeof(idx), fp)/250;
  259.     fclose(fp);
  260.     file_open("object.dat");
  261.     same_check();
  262.     save_r(buffer);
  263.     SPR_init();
  264.     SPR_display(1, 160);
  265.     sprite_erase();
  266.     SPR_setPaletteBlock(256, 256, col);
  267.     display_main();
  268.     SPR_display(2, 160);
  269.     SPR_display(0, 1024);
  270.     load_r(buffer);
  271.     fclose(fp);
  272. }
  273.